layui.define
(['dtree'], function (exports) {
	/* 定义object对象【start】 */
	var object = {
		init: function (c) {this.f(c);this.load();return object;},
		c: {data:[]}, // 配置项
		f: function (c) { // 数据初始化
			var s = new Date().getTime(),t = this;
			/* YsGrid基本配置，格式：
			{
				"id": "id_form_for_search",
				"conditions": [{}]
			}
			 */
			t.c = c;
			t.c.menuId = c.menuId;
			t.c.id_tree = c.id_tree;
			t.c.parentObj = c.parentObj
		},
		load:function () { // 加载控件
			this.loadTree();
		},
		loadTree:function () { // 添加监听
			var t = this;
			
			if(t.c.menuId == 12) { // 树加载-【PC功能配置】
				t.loadMenu12();
			} else if(t.c.menuId == 13) { // 树加载-【菜单管理】
				t.loadMenu13();
			} else if(t.c.menuId == 14) { // 树加载-【按钮管理】
				t.loadMenu14();
			} else if(t.c.menuId == 38) { // 树加载-【用户管理】
				t.loadMenu38();
			} else if(t.c.menuId == 49) { // 树加载-【弹出框管理】
				t.loadMenu49();
			} else if(t.c.menuId == 52) { // 树加载-【运营公司管理】
				t.loadMenu52();
			} else if(t.c.menuId == 78) { // 树加载-【技术规范维护】
				t.loadMenu78();
			} else if(t.c.menuId == 125) { // 树加载-【商品类目维护】
				t.loadMenu125();
			} else if(t.c.menuId == 10171) { // 树加载-【运营机构管理】
				t.loadMenu10171();
			} else if(t.c.menuId == 10182) { // 树加载-【组织机构管理】
				t.loadMenu10182();
			} else if(t.c.menuId == 10191) { // 树加载-【子列表配置管理】
				t.loadMenu10191();
			} else if(t.c.menuId == 10193) { // 树加载-【子列表按钮管理】
				t.loadMenu10193();
			}
	    },
	    loadMenu12: function() {
			var t = this;
			
			// 初始化树
			var DemoTree = layui.dtree.render({
				elem: "#" + t.c.id_tree,
				url: '/api/inter/ysCol/dtree',
				initLevel: "1",
				icon: -1,
				toolbar:true,
				toolbarWay:"follow",
				toolbarShow:[],
				width:'100%',
				menubar:true,
				menubarTips:{
					group:["refresh"]
				},
				toolbarExt: [{
					toolbarId: "addMenuOne",
					icon: "dtree-icon-add-circle",
					title: "新增字段",
					handler: function (node, $div) {
						var content, title, url;
						if (node.level == 1 ||node.level == 2) {
							layer.msg('非三级菜单无法新增');
							return;
						} else if (node.level == 3) {
							layer.open({
								type: 2,
								title: "新增字段",
								area: ['95%', '90%'],
								content: '/web/sys/ysCol/toAdd?menuId=' + node.nodeId
							});
							return;
						}
					}
				},{
					toolbarId: "resort",
					icon: "dtree-icon-sort",
					title: "调整字段顺序",
					handler: function (node, $div) {
						var content, title, url;
						if (node.level == 1 || node.level == 2) {
							layer.msg('非模块无需调整');
							return;
						} else {
							layer.open({
								type: 2,
								title: "调整字段顺序",
								area: ['95%', '90%'],
								content: '/web/sys/ysCol/toResort?menuId=' + node.nodeId
							});
							return false
						}
					}
				},{
					toolbarId: "setting",
					icon: "dtree-icon-set-sm",
					title: "设置菜单信息",
					handler: function (node, $div) {
						var content, title, url;
						if (node.level == 1 || node.level == 2) {
							layer.msg('非三级菜单无需设置');
							return;
						} else {
							layer.open({
								type: 2,
								title: "设置菜单信息",
								area: ['95%', '90%'],
								content: '/web/sys/ysMenu/toSetting?id=' + node.nodeId
							});
							return false
						}
					}
				},{
					toolbarId: "set-upload-col",
					icon: "dtree-icon-move-up",
					title: "设置上传字段",
					handler: function (node, $div) {
						var content, title, url;
						if (node.level == 1 || node.level == 2) {
							layer.msg('非三级菜单无需设置');
							return;
						} else {
							layer.open({
								type: 2,
								title: "设置上传字段",
								area: ['95%', '90%'],
								content: '/web/sys/ysCol/toSettingImport?menuId=' + node.nodeId
							});
							return false
						}
					}
				}]
			});
			
			// 绑定节点点击
			layui.dtree.on("node('" + t.c.id_tree + "')" ,function(obj){
				var objd = obj.param;
				if (objd.level == 3) {
					
					t.c.parentObj.reloadGrid({
						menuId: objd.nodeId
					});
					return;
				} else {
					if(!obj.param.leaf){
						var $div = obj.dom;
						DemoTree.clickSpread($div);  //调用内置函数展开节点
					}
				}
			});
	    },
	    loadMenu13: function() {
			var t = this;
			
			// 初始化树
			var DemoTree = layui.dtree.render({
				elem: "#" + t.c.id_tree,
				url: '/api/inter/ysMenu/dtree',
				initLevel: "3",
				icon: -1,
				toolbar:true,
				toolbarWay:"follow",
				toolbarShow:[],
				width:'100%',
				menubar:true,
				menubarTips:{
					group:["refresh"]
				},
				toolbarExt: [{
					toolbarId: "addMenuOne",
					icon: "dtree-icon-add-circle",
					title: "新增菜单",
					handler: function (node, $div) {
						console.log(node.level);
						var content, title, url;
						if (node.level == 1 || node.level == 2) {
							layer.open({
								type: 2,
								title: "新增菜单",
								area: ['95%', '90%'],
								content: '/web/sys/ysMenu/toAdd?pid=' + node.nodeId
							});
						} else {
							layer.msg('非子菜单无法新增模块');
							return false
						}
					}
				},{
					toolbarId: "move",
					icon: "dtree-icon-move-up",
					title: "移动",
					handler: function (node, $div) {
						var content, title, url;
						if (node.level == 2 || node.level == 3) {
							layer.open({
								type: 2,
								title: "移动菜单",
								area: ['95%', '90%'],
								content: '/web/sys/ysMenu/toMove?id=' + node.nodeId
							});
						} else {
							layer.msg('一级菜单无法移动');
							return false
						}
					}
				},{
					toolbarId: "resort",
					icon: "dtree-icon-sort",
					title: "调整菜单顺序",
					handler: function (node, $div) {
						var content, title, url;
						if (node.level == 1 || node.level == 2) {
							layer.open({
								type: 2,
								title: "调整菜单顺序",
								area: ['95%', '90%'],
								content: '/web/sys/ysMenu/toResort?pid=' + node.nodeId
							});
						} else {
							layer.msg('非子菜单无法调整');
							return false
						}
					}
				}]
			});
			
			// 绑定节点点击
			layui.dtree.on("node('" + t.c.id_tree + "')" ,function(obj){
				var objd = obj.param;
				
				t.c.parentObj.reloadGrid({
					menuId: objd.nodeId
				});
			});
	    },
	    loadMenu14: function() {
			var t = this;
			
			// 初始化树
			var DemoTree = layui.dtree.render({
				elem: "#" + t.c.id_tree,
				url: '/api/inter/ysButton/dtree',
				initLevel: "1",
				icon: -1,
				toolbar:true,
				toolbarWay:"follow",
				toolbarShow:[],
				width:'100%',
				menubar:true,
				menubarTips:{
					group:["refresh"]
				},
				toolbarExt: [{
					toolbarId: "addMenuOne",
					icon: "dtree-icon-add-circle",
					title: "新增按钮",
					handler: function (node, $div) {
						console.log(node.level);
						var content, title, url;
						if (node.level == 3) {
							layer.open({
								type: 2,
								title: "新增按钮",
								area: ['95%', '90%'],
								content: '/web/sys/ysButton/toAdd?menuId=' + node.nodeId
							});
						} else {
							layer.msg('非模块无法新增按钮');
							return false
						}
					}
				},{
					toolbarId: "resort",
					icon: "dtree-icon-sort",
					title: "调整按钮顺序",
					handler: function (node, $div) {
						var content, title, url;
						if (node.level == 3) {
							layer.open({
								type: 2,
								title: "调整模块顺序",
								area: ['95%', '90%'],
								content: '/web/sys/ysButton/toResort?guidModule=' + node.nodeId
							});
						} else {
							layer.msg('非子菜单无法调整');
							return false
						}
					}
				}]
			});
			
			// 绑定节点点击
			layui.dtree.on("node('" + t.c.id_tree + "')" ,function(obj){
				var objd = obj.param;
				if (objd.level == 3) {
					
					t.c.parentObj.reloadGrid({
						menuId: objd.nodeId
					});
					return;
				} else {
					if(!obj.param.leaf){
						var $div = obj.dom;
						DemoTree.clickSpread($div);  //调用内置函数展开节点
					}
				}
			});
	    },
	    loadMenu38: function() {
			var t = this;
			
			// 初始化树
			var DemoTree = layui.dtree.render({
				elem: "#" + t.c.id_tree,
				url: '/api/inter/tsUserInfo/dtree',
				initLevel: "2",
				icon: -1,
				toolbar:true,
				toolbarWay:"follow",
				toolbarShow:[],
				width:'100%',
				menubar:true,
				menubarTips:{
					group:["refresh"]
				},
				toolbarExt: []
			});
			
			// 绑定节点点击
			layui.dtree.on("node('" + t.c.id_tree + "')" ,function(obj){
				var objd = obj.param;
				
				t.c.parentObj.reloadGrid({
					nodeId: objd.nodeId
				});
				return;
			});
	    },
	    loadMenu49: function() {
			var t = this;
			
			// 初始化树
			var DemoTree = layui.dtree.render({
				elem: "#" + t.c.id_tree,
				url: '/api/inter/ysModalSelectorField/dtree',
				initLevel: "1",
				icon: -1,
				toolbar:true,
				toolbarWay:"follow",
				toolbarShow:[],
				width:'100%',
				menubar:true,
				menubarTips:{
					group:["refresh", {
						menubarId: "add",  // 按钮的唯一ID
						icon: "dtree-icon-roundadd", // 从dtreefont库中选取
						title: "新增弹出框",  // 按钮的提示标题
						handler: function(node, $div){  //扩展按钮的回调函数
							layer.open({
								type: 2,
								title: "新增弹出框",
								area: ['95%', '90%'],
								content: '/web/sys/ysModalSelector/toAdd'
							});
						}
					}]
				},
				toolbarExt: [{
					toolbarId: "edit",
					icon: "dtree-icon-bianji",
					title: "编辑此弹出框",
					handler: function (node, $div) {
						layer.open({
							type: 2,
							title: "设置弹出框信息",
							area: ['95%', '90%'],
							content: '/web/sys/ysModalSelector/toEdit?id=' + node.nodeId
						});
						return false
					}
				}, {
					toolbarId: "addMenuOne",
					icon: "dtree-icon-add-circle",
					title: "新增字段",
					handler: function (node, $div) {
						layer.open({
							type: 2,
							title: "新增字段",
							area: ['95%', '90%'],
							content: '/web/sys/ysModalSelectorField/toAdd?pid=' + node.nodeId
						});
						return;
					}
				},{
					toolbarId: "resort",
					icon: "dtree-icon-sort",
					title: "调整字段顺序",
					handler: function (node, $div) {
						layer.open({
							type: 2,
							title: "调整字段顺序",
							area: ['95%', '90%'],
							content: '/web/sys/ysModalSelectorField/toResort?pid=' + node.nodeId
						});
						return false
					}
				}]
			});
			
			// 绑定节点点击
			layui.dtree.on("node('" + t.c.id_tree + "')" ,function(obj){
				var objd = obj.param;
				
				t.c.parentObj.reloadGrid({
					pid: objd.nodeId
				});
			});
	    },
	    loadMenu52: function() {
			var t = this;
			
			// 初始化树
			var DemoTree = layui.dtree.render({
				elem: "#" + t.c.id_tree,
				url: '/api/inter/thrOperateCompanyInfo/dtree',
				initLevel: "2",
				icon: -1,
				toolbar:true,
				toolbarWay:"follow",
				toolbarShow:[],
				width:'100%',
				menubar:true,
				menubarTips:{
					group:["refresh"]
				},
				toolbarExt: [{
					toolbarId: "resort",
					icon: "dtree-icon-sort",
					title: "暂不开通此功能",
					handler: function (node, $div) {
						return false;
						var content, title, url;
						if (node.level == 1 || node.level == 2) {
							layer.open({
								type: 2,
								title: "调整菜单顺序",
								area: ['95%', '90%'],
								content: '/web/sys/ysMenu/toResort?pid=' + node.nodeId
							});
						} else {
							layer.msg('非子菜单无法调整');
							return false
						}
					}
				}]
			});
			
			// 绑定节点点击
			layui.dtree.on("node('" + t.c.id_tree + "')" ,function(obj){
				var objd = obj.param;
				
				t.c.parentObj.reloadGrid({
					id: objd.nodeId
				});
			});
	    },
	    loadMenu78: function() {
			var t = this;
			
			// 初始化树
			var DemoTree = layui.dtree.render({
				elem: "#" + t.c.id_tree,
				url: '/api/inter/newsItem/dtree',
				initLevel: "3",
				icon: -1,
				toolbar:true,
				toolbarWay:"follow",
				toolbarShow:[],
				width:'100%',
				menubar:true,
				menubarTips:{
					group:["refresh", {
						menubarId: "add_one",  // 按钮的唯一ID
						icon: "dtree-icon-roundadd", // 从dtreefont库中选取
						title: "新增一级栏目",  // 按钮的提示标题
						handler: function(node, $div){  //扩展按钮的回调函数
							layer.open({
								type: 2,
								title: "新增一级栏目",
								area: ['95%', '90%'],
								content: '/web/news/newsItem/toAdd?pid=0'
							});
						}
					}, {
						menubarId: "adjust_sort",  // 按钮的唯一ID
						icon: "dtree-icon-sort", // 从dtreefont库中选取
						title: "调整栏目顺序",  // 按钮的提示标题
						handler: function(node, $div){  //扩展按钮的回调函数
							layer.open({
								type: 2,
								title: "调整栏目顺序",
								area: ['95%', '90%'],
								content: '/web/news/newsItem/toResort?pid=0'
							});
						}
					}]
				},
				toolbarExt: [{
					toolbarId: "addMenuOne",
					icon: "dtree-icon-add-circle",
					title: "新增栏目",
					handler: function (node, $div) {
						console.log(node.level);
						var content, title, url;
						if (node.level == 1 || node.level == 2) {
							layer.open({
								type: 2,
								title: "新增栏目",
								area: ['95%', '90%'],
								content: '/web/news/newsItem/toAdd?pid=' + node.nodeId
							});
						} else {
							layer.msg('非子栏目无法新增模块');
							return false
						}
					}
				},{
					toolbarId: "resort",
					icon: "dtree-icon-sort",
					title: "调整子栏目顺序",
					handler: function (node, $div) {
						var content, title, url;
						if (node.level == 1 || node.level == 2) {
							layer.open({
								type: 2,
								title: "调整子栏目顺序",
								area: ['95%', '90%'],
								content: '/web/news/newsItem/toResort?pid=' + node.nodeId
							});
						} else {
							layer.msg('非子菜单无法调整');
							return false
						}
					}
				},{
					toolbarId: "setting",
					icon: "dtree-icon-set-sm",
					title: "编辑栏目信息",
					handler: function (node, $div) {
						layer.open({
							type: 2,
							title: "编辑栏目信息",
							area: ['95%', '90%'],
							content: '/web/news/newsItem/toEdit?id=' + node.nodeId
						});
						return false
					}
				}]
			});
			
			// 绑定节点点击
			layui.dtree.on("node('" + t.c.id_tree + "')" ,function(obj){
				var objd = obj.param;
				
				t.c.parentObj.reloadGrid({
					menuId: objd.nodeId
				});
			});
	    },
	    loadMenu125: function() {
			var t = this;
			
			// 初始化树
			var DemoTree = layui.dtree.render({
				elem: "#" + t.c.id_tree,
                url: '/api/inter/tbBaseinfoLmwh/dtree',
                initLevel: "2",
				icon: -1,
                toolbar:true,
                toolbarWay:"follow",
                toolbarShow:[],
                width:'100%',
                menubar:true,
                menubarTips:{
                    group:["refresh"]
                },
                toolbarExt: [{
                    toolbarId: "add",
                    icon: "dtree-icon-add-circle",
                    title: "新增子级",
                    handler: function (node, $div) {
                        var content, title, url;
                        layer.open({
                            type: 2,
                            title: "新增子级",
                            area: ['95%', '90%'],
                            content: '/web/business/tbBaseinfoLmwh/toAdd?pid=' + node.nodeId
                        });
                    }
                }]
            });
			
			// 绑定节点点击
			layui.dtree.on("node('" + t.c.id_tree + "')" ,function(obj){
				var objd = obj.param;
				
				t.c.parentObj.reloadGrid({
                    guidTsOrganizationInfo: objd.nodeId
                });
			});
	    },
	    loadMenu10171: function() {
			var t = this;
			
			// 初始化树
			var DemoTree = layui.dtree.render({
				elem: "#" + t.c.id_tree,
				url: '/api/inter/tsOperateOrg/dtree',
				initLevel: "3",
				icon: -1,
				toolbar:true,
				toolbarWay:"follow",
				toolbarShow:[],
				width:'100%',
				menubar:true,
				menubarTips:{
					group:["refresh"]
				},
				toolbarExt: [{
					toolbarId: "addMenuOne",
					icon: "dtree-icon-add-circle",
					title: "新增子机构",
					handler: function (node, $div) {
						console.log(node.level);
						var content, title, url;
						layer.open({
							type: 2,
							title: "新增子运营机构",
							area: ['95%', '90%'],
							content: '/web/sys/tsOperateOrg/toAdd?pid=' + node.nodeId
						});
					}
				},{
					toolbarId: "move",
					icon: "dtree-icon-move-up",
					title: "移动",
					handler: function (node, $div) {
						var content, title, url;
						if (node.level == 2 || node.level == 3) {
							layer.open({
								type: 2,
								title: "移动运营机构",
								area: ['95%', '90%'],
								content: '/web/sys/tsOperateOrg/toMove?id=' + node.nodeId
							});
						} else {
							layer.msg('一级菜单无法移动');
							return false
						}
					}
				}]
			});
			
			// 绑定节点点击
			layui.dtree.on("node('" + t.c.id_tree + "')" ,function(obj){
				var objd = obj.param;
				
				t.c.parentObj.reloadGrid({
					nodeId: objd.nodeId
				});
			});
	    },
	    loadMenu10182: function() {
			var t = this;
			
			// 初始化树
			var DemoTree = layui.dtree.render({
				elem: "#" + t.c.id_tree,
				url: '/api/inter/tsOrganizationInfo/dtree',
				initLevel: "2",
				icon: -1,
				toolbar:true,
				toolbarWay:"follow",
				toolbarShow:[],
				width:'100%',
				menubar:true,
				menubarTips:{
					group:["refresh"]
				},
				toolbarExt: [{
					toolbarId: "add",
					icon: "dtree-icon-add-circle",
					title: "新增子机构",
					handler: function (node, $div) {
						var content, title, url;
						layer.open({
							type: 2,
							title: "新增子机构",
							area: ['95%', '90%'],
							content: '/web/sys/tsOrganizationInfo/toAdd?pid=' + node.nodeId
						});
					}
				}]
			});
			
			// 绑定节点点击
			layui.dtree.on("node('" + t.c.id_tree + "')" ,function(obj){
				var objd = obj.param;
				
				t.c.parentObj.reloadGrid({
					nodeId: objd.nodeId
				});
			});
	    },
	    loadMenu10191: function() {
			var t = this;
			
			// 初始化树
			var DemoTree = layui.dtree.render({
				elem: "#" + t.c.id_tree,
				url: '/api/inter/ysGrid/dtree',
				initLevel: "1",
				icon: -1,
				toolbar:true,
				toolbarWay:"follow",
				toolbarShow:[],
				width:'100%',
				menubar:true,
				menubarTips:{
					group:["refresh"]
				},
				toolbarExt: [{
					toolbarId: "addGridCol",
					icon: "dtree-icon-add-circle",
					title: "新增字段",
					handler: function (node, $div) {
						layer.open({
							type: 2,
							title: "新增字段",
							area: ['95%', '90%'],
							content: '/web/sys/ysGridCol/toAdd?gridId=' + node.nodeId
						});
						return;
					}
				},{
					toolbarId: "resort",
					icon: "dtree-icon-sort",
					title: "调整字段顺序",
					handler: function (node, $div) {
						var content, title, url;
						if (node.level == 1 || node.level == 2) {
							layer.msg('非模块无需调整');
							return;
						} else {
							layer.open({
								type: 2,
								title: "调整字段顺序",
								area: ['95%', '90%'],
								content: '/web/sys/ysGridCol/toResort?gridId=' + node.nodeId
							});
							return false
						}
					}
				},{
					toolbarId: "setting",
					icon: "dtree-icon-set-sm",
					title: "设置菜单信息",
					handler: function (node, $div) {
						var content, title, url;
						if (node.level == 1 || node.level == 2) {
							layer.msg('非三级菜单无需设置');
							return;
						} else {
							layer.open({
								type: 2,
								title: "设置菜单信息",
								area: ['95%', '90%'],
								content: '/web/sys/ysGrid/toSetting?id=' + node.nodeId
							});
							return false
						}
					}
				}]
			});
			
			// 绑定节点点击
			layui.dtree.on("node('" + t.c.id_tree + "')" ,function(obj){
				var objd = obj.param;
				
				t.c.parentObj.reloadGrid({
					gridId: objd.nodeId
				});
				return;
			});
	    },
	    loadMenu10193: function() {
			var t = this;
			
			// 初始化树
			var DemoTree = layui.dtree.render({
				elem: "#" + t.c.id_tree,
				url: '/api/inter/ysGrid/dtreeForGridButton',
				initLevel: "1",
				icon: -1,
				toolbar:true,
				toolbarWay:"follow",
				toolbarShow:[],
				width:'100%',
				menubar:true,
				menubarTips:{
					group:["refresh"]
				},
				toolbarExt: [{
					toolbarId: "addGridButton",
					icon: "dtree-icon-add-circle",
					title: "新增按钮",
					handler: function (node, $div) {
						layer.open({
							type: 2,
							title: "新增按钮",
							area: ['95%', '90%'],
							content: '/web/sys/ysGridButton/toAdd?gridId=' + node.nodeId
						});
						return;
					}
				},{
					toolbarId: "resort",
					icon: "dtree-icon-sort",
					title: "调整按钮顺序",
					handler: function (node, $div) {
						var content, title, url;
						if (node.level == 1 || node.level == 2) {
							layer.msg('非模块无需调整');
							return;
						} else {
							layer.open({
								type: 2,
								title: "调整字段顺序",
								area: ['95%', '90%'],
								content: '/web/sys/ysGridButton/toResort?gridId=' + node.nodeId
							});
							return false
						}
					}
				}]
			});
			
			// 绑定节点点击
			layui.dtree.on("node('" + t.c.id_tree + "')" ,function(obj){
				var objd = obj.param;
				
				t.c.parentObj.reloadGrid({
					gridId: objd.nodeId
				});
				return;
			});
	    }
	};
	/* 定义object对象【end】 */
	
	
	exports('YsGridTree', object);
});